require(["core", "http://res.wx.qq.com/open/js/jweixin-1.0.0.js", "coAjax"], function(jSouper, wx, coAjax) {
	var appid;

	coAjax.get(appConfig.wx.jsapi_signature, function(result) {
		var config = result.result;
		console.log(config);
		config.debug = true;
		config.jsApiList = [
			"onMenuShareTimeline",
			"onMenuShareAppMessage",
			"onMenuShareQQ",
			"onMenuShareWeibo",
			"startRecord",
			"stopRecord",
			"onVoiceRecordEnd",
			"playVoice",
			"pauseVoice",
			"stopVoice",
			"onVoicePlayEnd",
			"uploadVoice",
			"downloadVoice",
			"chooseImage",
			"previewImage",
			"uploadImage",
			"downloadImage",
			"translateVoice",
			"getNetworkType",
			"openLocation",
			"getLocation",
			"hideOptionMenu",
			"showOptionMenu",
			"hideMenuItems",
			"showMenuItems",
			"hideAllNonBaseMenuItem",
			"showAllNonBaseMenuItem",
			"closeWindow",
			"scanQRCode",
			"chooseWXPay",
			"openProductSpecificView",
			"addCard",
			"chooseCard",
			"openCard"
		];
		wx.config(config);
		window.wx_config = config;
	});
	App.set("$Event.wx.pay", function() {
		alert("通过统一下单接口下单");
		coAjax.post(appConfig.wx.js_unified_order, {
			ach_id: App.get("$Cache.wx.ach_id"),
			detail: "支付测试"
		}, function(result) {
			var wx_pay = result.result;

			alert("发起支付请求");
			wx.chooseWXPay({
				timestamp: wx_pay.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
				nonceStr: wx_pay.nonceStr, // 支付签名随机串，不长于 32 位
				package: wx_pay.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
				signType: wx_pay.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
				paySign: wx_pay.paySign, // 支付签名
				success: function(res) {
					// 支付成功后的回调函数
					alert("支付成功");
				}
			});
		});
	});
	App.set("$Event.wx.get_open_id", function() {
		location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wx_config.appId +
			"&redirect_uri=" + encodeURIComponent("http://api.dotnar.com/wx/authorize/notify_url") +
			"&response_type=code&scope=snsapi_userinfo&state=" + encodeURIComponent(location.href) +
			"#wechat_redirect";
	});
});